package com.bincloud.vue.admin.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * 跨域配置
 * @author bincloud, mvpzhou
 */
@Configuration
public class CorsConfig {
    @Bean
    public CorsFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        //允许域名跨域
        config.addAllowedOrigin("*");
        //允许cookie
        config.setAllowCredentials(true);
        //允许原始头信息
        config.addAllowedHeader("*");
        //允许请求方法跨域
        config.addAllowedMethod("*");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        // 配置过滤路径
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }
}
